﻿
using Demo_Chart图表样式.Service;
using Microsoft.Research.DynamicDataDisplay;
using Microsoft.Research.DynamicDataDisplay.DataSources;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace Demo_Chart图表样式.Model
{
    class ModelMainWindow : NotifyPropertyChange//逻辑
    {
        #region 建立单例

        private static ModelMainWindow uniqueInstance;

        private static readonly object locker = new object();

        public static ModelMainWindow GetInstance()
        {
            if (uniqueInstance == null)
            {
                lock (locker)
                {
                    if (uniqueInstance == null)
                    {
                        uniqueInstance = new ModelMainWindow();
                    }
                }
            }
            return uniqueInstance;
        }

        #endregion

        //=========================================

        public void ADD(int nIndex)
        {
            ObservableCollection<CsMultiple> m_L1 = new ObservableCollection<CsMultiple>();

            string strLineName = string.Empty;
            Color cLineColor = Colors.Black;
            switch (nIndex)
            {
                case 0: strLineName = "OriginLine"; cLineColor = Colors.Lime; break;
                case 1: strLineName = "ErrorLine"; cLineColor = Colors.Red; break;
                default: break;

            }

            m_L1.Add(new CsMultiple() { LOrigin = CreatData(), LineColor = cLineColor, LineName = strLineName });

            ((MainWindow)System.Windows.Application.Current.MainWindow).MyView.AddChartLine1(TheEndLineInformationCollection(m_L1), false);
        }

        private List<double> CreatData()//随机生成点
        {
            List<double> LLine = new List<double> { };
            int nLineCount = 12800;
            for (int i = 0; i < nLineCount; i++)
            {
                Random rd = new Random();
                LLine.Add(rd.Next(-100, 100));
            }
            return LLine;
        }

        //=========================================

        private ObservableCollection<CsSQLite> TheEndLineInformationCollection(ObservableCollection<CsMultiple> pL) //传入多个数据集合  //xy点的资源集合 点的集合 线条颜色 线条名字 
        {
            ObservableCollection<CsSQLite> L = new ObservableCollection<CsSQLite>();
            int nDatCountData = pL.Count();
            for (int i = 0; i < nDatCountData; i++)
                L.Add(new CsSQLite() { LinePointXY = CreatPointLineXY(pL[i].LOrigin), LineColor = pL[i].LineColor, LineName = pL[i].LineName });
            return L;
        }

        private ObservableDataSource<Point> CreatPointLineXY(List<double> pL)
        {
            ObservableDataSource<Point> L = new ObservableDataSource<Point>();
            pL.IndexOf(0, 0);
            int LCount = pL.Count();
            for (int j = 0; j < LCount; j++)
            {
                Point[] pData = new Point[1];
                pData[0] = new Point(j, pL[j]);
                L.AppendMany(pData);
            }
            return L;
        }


    }
}
